from django.db import models

from Apps.util.snowFlake import get_guid


# Create your models here.

class Demo(models.Model):
    id = models.CharField(max_length=20, primary_key=True, default=get_guid, editable=False)
    name = models.CharField(max_length=20)
    age = models.IntegerField()
    sex = models.SmallIntegerField(verbose_name='性别', choices=((1, '男'), (2, '女')), default=1)
    birthday = models.DateField(auto_now=True)
    ctime = models.DateTimeField(auto_now_add=True)
    keyforeign = models.ForeignKey(to='Demo', on_delete=models.DO_NOTHING, null=True)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'demo'
        verbose_name = db_table
        verbose_name_plural = db_table
        ordering = ['-age']
        unique_together = ('name', 'age')
        index_together = ('name', 'age')


class Person(models.Model):
    id = models.CharField(max_length=20, primary_key=True, default=get_guid, editable=False)
    name = models.CharField(max_length=30)
    age = models.IntegerField()
    demo = models.ForeignKey(Demo, on_delete=models.CASCADE)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'Person'


class Dog(models.Model):
    id = models.CharField(max_length=20, primary_key=True, default=get_guid, editable=False)
    name = models.CharField(max_length=30)
    age = models.IntegerField()
    demo = models.ManyToManyField(Demo)

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'dog'
